﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AdaptiveAgents.Tools
{
    class ProbabilityCreatorSecondVersion : IProbabilityCreator
    {
        private double m_dEpsilon;

        public ProbabilityCreatorSecondVersion(double epsilon) { m_dEpsilon = epsilon; }

        public double getEpsilonTo0(int myLevel, int otherLevel)
        {
            if ((myLevel == otherLevel) && (myLevel == 2))
            {
                return 1 - m_dEpsilon;
            }
            else if ((myLevel == otherLevel) && (myLevel != 2))
            {
                return 0;
            }else if(myLevel == 0)
            {
                return lowLevelToOtherProbability(otherLevel);
            }
            else if (myLevel == 1)
            {
                return middleLevelToOtherProbability(otherLevel);
            }
            else
            {
                return highLevelToOtherProbability(otherLevel);
            }

        }

        public double getEpsilonTo1(int myLevel, int otherLevel)
        {
            if ((myLevel == otherLevel) && (myLevel == 2))
            {
                return 1 - m_dEpsilon;
            }
            else if ((myLevel == otherLevel) && (myLevel != 2))
            {
                return 0;
            }
            else if (myLevel == 0)
            {
                return lowLevelToOtherProbability(otherLevel);
            }
            else if (myLevel == 1)
            {
                return middleLevelToOtherProbability(otherLevel);
            }
            else
            {
                return highLevelToOtherProbability(otherLevel);
            }
        }

        public double getEpsilonTo2(int myLevel, int otherLevel)
        {
            if ((myLevel == otherLevel) && (myLevel == 2))
            {
                return 1 - m_dEpsilon;
            }
            else if ((myLevel == otherLevel) && (myLevel != 2))
            {
                return 0;
            }
            else if (myLevel == 0)
            {
                return lowLevelToOtherProbability(otherLevel);
            }
            else if (myLevel == 1)
            {
                return middleLevelToOtherProbability(otherLevel);
            }
            else
            {
                return highLevelToOtherProbability(otherLevel);
            }
        }

        private double lowLevelToOtherProbability(int otherLevel)
        {
            if (otherLevel == 0) { return 0; }
            else if (otherLevel == 1) { return m_dEpsilon / 2; }
            else { return (1 - m_dEpsilon) + (m_dEpsilon / 2); }
        }

        private double middleLevelToOtherProbability(int otherLevel)
        {
            if (otherLevel == 0) { return m_dEpsilon / 2; }
            else if (otherLevel == 1) { return 0; }
            else { return (1 - m_dEpsilon) + (m_dEpsilon / 2); }
        }

        private double highLevelToOtherProbability(int otherLevel)
        {
            if (otherLevel == 0) { return m_dEpsilon / 2; }
            else if (otherLevel == 1) { return m_dEpsilon / 2; }
            else { return 1 - m_dEpsilon; }
        }

    }
}
